package com.hrm.social.service;

import com.hrm.common.entity.PageResult;
import com.hrm.domain.social_security.UserSocialSecurity;
import com.hrm.social.dao.UserSocialSecurityDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.Optional;

@Service
public class UserSocialService {

    @Autowired
    private UserSocialSecurityDao userSocialSecurityDao;


    public PageResult<Map<String, Object>> findAll(Integer page, Integer pageSize, String companyId) {
        Page<Map<String, Object>> mapPage = userSocialSecurityDao.findPage(companyId, PageRequest.of(page - 1, pageSize));
        return new PageResult<>(mapPage.getTotalElements(), mapPage.getContent());
    }

    public UserSocialSecurity findById(String id) {
        Optional<UserSocialSecurity> optional = userSocialSecurityDao.findById(id);
        return optional.orElse(null);
    }

    public void save(UserSocialSecurity userSocialSecurity) {
        userSocialSecurityDao.save(userSocialSecurity);
    }
}
